package com.lqk.principle.inversion.improve;

/**
 * @author lqk
 * @date 2021/11/25 19:50
 */
public class DependencyInversionImp {
    public static void main(String[] args) {
        // 客户端无需改变
        Person person = new Person();
        person.receive(new Email());
        person.receive(new WeiXin());
    }
}

class Email implements IReceiver{
    public String getInfo(){
        return "电子邮件信息：hello，world";
    }
}

class WeiXin implements IReceiver{
    public String getInfo(){
        return "微信信息：hello，world";
    }
}

// 完成 Person 接收消息的功能
// 方式2

// 定义接口
interface IReceiver {
    String getInfo();
}

// 实现接口
class Person {
    public void receive(IReceiver receiver){
        System.out.println(receiver.getInfo());
    }
}


